home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MOR55SRC.ZIP / MORIA / SOURCE / STAFFS.C < prev    next >
C/C++ Source or Header  |  1992-12-07  |  4KB  |  185 lines

  1. /* source/staffs.c: staff code
  2.  
  3.    Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  4.  
  5.    This software may be copied and distributed for educational, research, and
  6.    not for profit purposes provided that this copyright and statement are
  7.    included in all such copies. */
  8.  
  9. #include "config.h"
  10. #include "constant.h"
  11. #include "types.h"
  12. #include "externs.h"
  13.  
  14. #ifdef USG
  15. #include <string.h>
  16. #else
  17. #include <strings.h>
  18. #endif
  19.  
  20.  
  21. /* Use a staff.                    -RAK-    */
  22. void use()
  23. {
  24.   int32u i;
  25.   int j, k, item_val, chance, y, x;
  26.   register int ident;
  27.   register struct misc *m_ptr;
  28.   register inven_type *i_ptr;
  29.  
  30.   free_turn_flag = TRUE;
  31.   if (inven_ctr == 0)
  32.     msg_print("But you are not carrying anything.");
  33.   else if (!find_range(TV_STAFF, TV_NEVER, &j, &k))
  34.     msg_print("You are not carrying any staffs.");
  35.   else if (get_item(&item_val, "Use which staff?", j, k, CNIL, CNIL))
  36.     {
  37.       i_ptr = &inventory[item_val];
  38.       free_turn_flag = FALSE;
  39.       m_ptr = &py.misc;
  40.       chance = m_ptr->save + stat_adj(A_INT) - (int)i_ptr->level - 5
  41.     + (class_level_adj[m_ptr->pclass][CLA_DEVICE] * m_ptr->lev / 3);
  42.       if (py.flags.confused > 0)
  43.     chance = chance / 2;
  44.       if ((chance < USE_DEVICE) && (randint(USE_DEVICE - chance + 1) == 1))
  45.     chance = USE_DEVICE; /* Give everyone a slight chance */
  46.       if (chance <= 0)    chance = 1;
  47.       if (randint(chance) < USE_DEVICE)
  48.     msg_print("You failed to use the staff properly.");
  49.       else if (i_ptr->p1 > 0)
  50.     {
  51.       i = i_ptr->flags;
  52.       ident = FALSE;
  53.       (i_ptr->p1)--;
  54.       while (i != 0)
  55.         {
  56.           j = bit_pos(&i) + 1;
  57.           /* Staffs.                */
  58.           switch(j)
  59.         {
  60.         case 1:
  61.           ident = light_area(char_row, char_col);
  62.           break;
  63.         case 2:
  64.           ident = detect_sdoor();
  65.           break;
  66.         case 3:
  67.           ident = detect_trap();
  68.           break;
  69.         case 4:
  70.           ident = detect_treasure();
  71.           break;
  72.         case 5:
  73.           ident = detect_object();
  74.           break;
  75.         case 6:
  76.           teleport(100);
  77.           ident = TRUE;
  78.           break;
  79.         case 7:
  80.           ident = TRUE;
  81.           earthquake();
  82.           break;
  83.         case 8:
  84.           ident = FALSE;
  85.           for (k = 0; k < randint(4); k++)
  86.             {
  87.               y = char_row;
  88.               x = char_col;
  89.               ident |= summon_monster(&y, &x, FALSE);
  90.             }
  91.           break;
  92.         case 10:
  93.           ident = TRUE;
  94.           destroy_area(char_row, char_col);
  95.           break;
  96.         case 11:
  97.           ident = TRUE;
  98.           starlite(char_row, char_col);
  99.           break;
  100.         case 12:
  101.           ident = speed_monsters(1);
  102.           break;
  103.         case 13:
  104.           ident = speed_monsters(-1);
  105.           break;
  106.         case 14:
  107.           ident = sleep_monsters2();
  108.           break;
  109.         case 15:
  110.           ident = hp_player(randint(8));
  111.           break;
  112.         case 16:
  113.           ident = detect_invisible();
  114.           break;
  115.         case 17:
  116.           if (py.flags.fast == 0)
  117.             ident = TRUE;
  118.           py.flags.fast += randint(30) + 15;
  119.           break;
  120.         case 18:
  121.           if (py.flags.slow == 0)
  122.             ident = TRUE;
  123.           py.flags.slow += randint(30) + 15;
  124.           break;
  125.         case 19:
  126.           ident = mass_poly();
  127.           break;
  128.         case 20:
  129.           if (remove_curse())
  130.             {
  131.               if (py.flags.blind < 1)
  132.             msg_print("The staff glows blue for a moment..");
  133.               ident = TRUE;
  134.             }
  135.           break;
  136.         case 21:
  137.           ident = detect_evil();
  138.           break;
  139.         case 22:
  140.           if ((cure_blindness()) || (cure_poison()) ||
  141.               (cure_confusion()))
  142.             ident = TRUE;
  143.           break;
  144.         case 23:
  145.           ident = dispel_creature(CD_EVIL, 60);
  146.           break;
  147.         case 25:
  148.           ident = unlight_area(char_row, char_col);
  149.           break;
  150.         case 32:
  151.           /* store bought flag */
  152.           break;
  153.         default:
  154.           msg_print("Internal error in staffs()");
  155.           break;
  156.         }
  157.           /* End of staff actions.        */
  158.         }
  159.       if (ident)
  160.         {
  161.           if (!known1_p(i_ptr))
  162.         {
  163.           m_ptr = &py.misc;
  164.           /* round half-way case up */
  165.           m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) /
  166.             m_ptr->lev;
  167.           prt_experience();
  168.  
  169.           identify(&item_val);
  170.           i_ptr = &inventory[item_val];
  171.         }
  172.         }
  173.       else if (!known1_p(i_ptr))
  174.         sample (i_ptr);
  175.       desc_charges(item_val);
  176.     }
  177.       else
  178.     {
  179.       msg_print("The staff has no charges left.");
  180.       if (!known2_p(i_ptr))
  181.         add_inscribe(i_ptr, ID_EMPTY);
  182.     }
  183.     }
  184. }
  185.